

/*
数组去重，注意的是，{}与{}，[]与[]，1与'1'不是相同元素

 */




let arr = [false, true, undefined, null, NaN, NaN,[],[],{}, {},'a','a','a','g','q','d','a','e','q',1,'1','1'];

function unique(arr){
    let hasObj = {}
    let result = []
    for(let i in arr){
        //如果是引用数据类型（[]、{}）和NaN，[] === []是false,{}==={}是false,NaN === NaN也是false
        if(typeof arr[i] ===  'object' || (typeof arr[i] === 'number' && isNaN(arr[i]))){
            hasObj[arr[i]] = false
            result.push(arr[i])
        }else if(!hasObj[arr[i]+ typeof  arr[i]]){ // 处理1和'1'的情况， 1 =='1'是false
            hasObj[arr[i] + typeof arr[i] ] = true
            result.push(arr[i])
        }
    }
    return result
}

console.log(unique(arr))